﻿using CinemaMaestro.BusinessLayer.Contracts;
using CinemaMaestro.DataLayer.Contracts;
using CinemaMaestro.DataLayer.Contracts.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CinemaMaestro.BusinessLayer
{
    public class Rooms : BusinessObjectBase, IRooms
    {
        public Rooms(IUnitOfWork uow)
            : base(uow)
        { }

        public Room Create(Room room)
        {
            var createdRoom = _uow.RoomRepository.Create(room);
            _uow.SaveChanges();
            return createdRoom;
        }

        public bool Delete(int id)
        {
            var deleted = _uow.RoomRepository.Delete(id);
            _uow.SaveChanges();
            return deleted;
        }

        public IQueryable<Room> Read()
        {
            return _uow.RoomRepository.Read();
        }

        public void Update(Room entity)
        {
            _uow.RoomRepository.Update(entity);
            _uow.SaveChanges();
        }

        public bool RoomHasRelationWithCinema(int cinemaId)
        {
            bool hasRelation = Read().Any(x => x.Cinema.Id == cinemaId);
            return hasRelation;
        }
    }
}
